﻿CREATE PROCEDURE [dbo].[yaf_category_listread](
                @BoardID    INT,
                @UserID     INT,
                @CategoryID INT  = NULL)
AS
    BEGIN
        SELECT   a.CategoryID,
                 a.Name
        FROM     yaf_Category a
                 JOIN yaf_Forum b
                   ON b.CategoryID = a.CategoryID
                 JOIN yaf_vaccess v
                   ON v.ForumID = b.ForumID
        WHERE    a.BoardID = @BoardID
        AND v.UserID = @UserID
        AND (v.ReadAccess <> 0
              OR (b.Flags & 2) = 0)
        AND (@CategoryID IS NULL 
              OR a.CategoryID = @CategoryID)
        AND b.ParentID IS NULL
        GROUP BY a.CategoryID,a.Name,a.SortOrder
        ORDER BY a.SortOrder
    END


